<template>
	<view class="">
		<view class="status_bar">
		          <!-- 这里是状态栏 -->
		</view>
		<view class="search content-padding" style="padding-right: 24rpx;">
			<image src="../../static/image/logo.png" mode="" class="logo" style=""></image>
			<uni-search-bar :radius="32" @confirm="search" bgColor="#F6F8F8" placeholder="请输入ID或者手机号" style="flex: 1;" ></uni-search-bar>
		</view>
		<view class="lunbo content-padding">
			<uni-swiper-dot :info="info" :current="current" :dotsStyles="lunboStyle" field="content" mode="round">
			    <swiper class="swiper-box" @change="change" style="height: 100%;" autoplay="true">
			        <swiper-item v-for="(item ,index) in info" :key="index">
			            <view class="swiper-item" style="width: 100%;height: 100%;" @tap="toInfo(item.id)">
			                <image :src="item.pic" mode="aspectFill" style="width: 100%;height: 100%;border-radius: 10rpx;" ></image>
			            </view>
			        </swiper-item>
			    </swiper>
			</uni-swiper-dot>
		</view>
		<view class="" style="margin-top: 24rpx;padding:0 18rpx;">
			<view class="shiyong" >
				<view class="shiyong1" @tap="shiyong()">
					<view class="shiyong11">
						<view class="shiyong111">免费试用</view>
						<image src="../../static/image/jiantou.png" mode="" class="shiyong112">
					</view>
					<view class="shiyong12">
						认证商家，平台保障
					</view>
				</view>
				<view  @tap="$util.toUrl('./fenxiang')" style="position:relative;top:-2%;flex:1;height: 108%;background: url(../../static/image/fenxiang.png) no-repeat;background-size: 100% 100%;">
					<view class="shiyong11">
						<view class="shiyong111">分享赚钱</view>
						<image src="../../static/image/jiantou.png" mode="" class="shiyong112">
					</view>
					<view class="shiyong12">
						多邀多赚，每天躺赚收益 
					</view>
				</view>
				<!-- <view class="shiyong2">
					<view class="shiyong21" @tap="$util.toUrl('./fenxiang')">
						<view class="shiyong11">
							<view class="shiyong211">分享赚钱</view>
							<image src="../../static/image/jiantou.png" mode="" class="shiyong112" style="margin-top:0;"></image>
						</view>
						<view class="shiyong2text">
							多邀多赚，每天躺赚收益
						</view>
					</view>
					<view class="shiyong22" @tap="toInfo('3')">
						<view class="shiyong11">
							<view class="shiyong211">积分墙</view>
							<image src="../../static/image/jiantou.png" mode="" class="shiyong112" style="margin-top:0;"></image>
						</view>
						<view class="shiyong2text">
							极速审核，立返现金
						</view>
					</view>
				</view> -->
			</view>
		</view>
		<!-- <view class="linghongbao" @tap="toInfo('3')">
			
		</view> -->
		<u-toast ref="uToast" />
		<!-- <u-modal v-model="versionshow" content="有新的版本,请确认是否更新" @confirm="xiazaiAnzhuang" :show-cancel-button="true"></u-modal> -->
	</view>
</template>

<script>
	import uniSearchBar from '@/components/uni-search-bar/uni-search-bar.vue'
	import uniSwiperDot from "@/components/uni-swiper-dot/uni-swiper-dot.vue"
	import permision from "@/js_sdk/wa-permission/permission.js"
	//引入插件
	// const sharetrace = uni.requireNativePlugin('shoot-sharetrace');

	export default {
		components: {
			uniSearchBar,
			uniSwiperDot
		},
		data() {
			return {
				info: [{
					content: '内容 A',
					pic:"../../static/image/banner.png"
				},
				{
					content: '内容 A',
					pic:"../../static/image/banner.png"
				}],
				current: 0,
				mode: 'round',
				lunboStyle:{
					'selectedBackgroundColor':'#fff',
					'border':'unset',
					'backgroundColor':'#fff',
					selectedBorder:'unset'
				},
				versionshow:false,
				version:uni.getStorageSync("version"),
				newversion:{}
			}
		}
		,onReady(){
			
			// let id = uni.getStorageSync("token");
			// if (id == undefined || id == '') {
			// 		this.$util.toUrl("/pages/login/login");
			// 		return;
			// }
			//获取版本信
			// var that = this;
			// this.$util.nuiAjax(this.$jiekou.getVersion, {}, function(res) {
			// 	if (res.result == "true") {
					
			// 		var version = {
			// 			versionUrl:res.versionUrl,
			// 			versionCode:res.versionCode,
			// 			versionSort:res.versionSort,
			// 			isQiangzhi:res.isQiangzhi
			// 		};
					
					
			// 		if(that.$jiekou.versionCode<Number(version.versionSort)){
			// 			that.version.isHave = true;
			// 			that.version.newUrl = res.versionUrl;
			// 			uni.setStorageSync("version",that.version)
			// 			that.newversion = version;
			// 			if(version.isQiangzhi==1){//强制更新，直接下
			// 				that.xiazaiAnzhuang();
			// 			}else{
			// 				that.versionshow = true ;
			// 			}
			// 		}else{
			// 			uni.setStorageSync("version",version);
			// 		}
					
					
					
			// 	}
			// })
			
		}
		, onLoad() {
			
			this.requestAndroidPermission('android.permission.CAMERA');
		
			
			var that = this;
			this.$util.nuiAjax(this.$jiekou.selectBanner,{},function(res){
				that.info = res.data;
			})
			const value = uni.getStorageSync('token');
			console.log(value);
			if (value == undefined || value == '' || value == null ) {
				// this.$util.toUrl("../login/login");
			}else{
				this.timLogin();
			}
			
			// uni.startPullDownRefresh();
		},
		onPullDownRefresh() {
			var that = this;
				this.$util.nuiAjax(this.$jiekou.selectBanner,{},function(res){
					that.info = res.data;
					uni.stopPullDownRefresh();
				})	
		},
		methods: {

			async requestAndroidPermission(permisionID) {
				var result = await permision.requestAndroidPermission(permisionID)
				var strStatus
				if (result == 1) {
					strStatus = "已获得授权"
				} else if (result == 0) {
					strStatus = "未获得授权"
				} else {
					strStatus = "被永久拒绝权限"
				}
				// uni.showModal({
				// 	content: permisionID + strStatus,
				// 	showCancel: false
				// });
			},
			shiyong:function(){
				var that = this;
				this.$util.nuiAjax(this.$jiekou.userInfo,{id:uni.getStorageSync("token")},function(res){
					if(res.result=="true"){
						uni.setStorageSync("userInfo",res.data);
						if(res.data.isTuijian==1){
							if(res.data.type==2){
								that.$util.toUrl('./shangjiaJihe');
							}else{
								that.$util.toUrl('./maijiashiyongJihe');
							}
							
						}else{
							that.$refs.uToast.show({
								title: '您尚无法使用该功能',
								duration: 2000
							})
						}
						
					}
				})
				
			},
			kaifazhong:function(){
				// this.$refs.uToast.show({
				// 	title: '功能开发中',
				// 	duration: 1000
				// })
				
				
			},
			showResult(data) {
				uni.showModal({
					title: 'ShareTrace',
					content: data,
					showCancel:false,
					success: function (res) {
						
					}
				});
			}
			,timLogin(){
				var that = this;
				let timtoken = uni.getStorageSync("timToken");
				let id = uni.getStorageSync("token");
				console.log("登陆token："+timtoken);
				let promise = that.tim.login({userID: id, userSig: timtoken});
				promise.then(function(imResponse) {
				  console.log(imResponse.data); // 登录成功
				  if (imResponse.data.repeatLogin === true) {
				    // 标识账号已登录，本次登录操作为重复登录。v2.5.1 起支持
				    console.log(imResponse.data.errorInfo);
				  }
				}).catch(function(imError) {
					console.log(JSON.stringify(imError));
					if(imError.code==70001){
						/**获取聊天token*/
						that.$util.nuiAjax(that.$jiekou.getTimToken, {
							userid: id
						}, function(res) {
							if (res.result == "true") {
								uni.setStorageSync("timToken", res.data);
								that.timLogin();
							}
						})
					}else{
						 console.warn('login error:', imError); // 登录失败的相关信息
					}
				 
				});
			},
			
			search(data){
				// this.$util.nuiAjax(this.$jiekou.selectUser,{keysearch:data.value},function(res){
				// 	that.info = res.data;
				// })
				if(data.value.trim()===""){
					return ;
				}
				this.$util.toUrl("./maijia?keysearch="+data.value);
			},
			change(e) {
				this.current = e.detail.current;
			},
			toInfo(id){
				console.log(1);
				this.$util.toUrl("./bannerInfo?id="+id);
			}
		}
	}
</script>

<style lang="scss">
	.linghongbao{
		height: 180rpx;
		margin: 14rpx 30rpx 24rpx 30rpx;
		background: url(../../static/image/linghongbao.png) no-repeat;
		background-size: 100% 100%;
	}
	.shiyong2text{
		height:34rpx;
		font-size:24rpx;
		font-weight:400;
		line-height:34rpx;
		text-shadow:0px 2rpx 4rpx rgba(216,60,62,1);
		margin-left: 36rpx;
	}
	.shiyong211{
		height:44rpx;
		font-size:32rpx;
		font-weight:500;
		line-height:44rpx;
		text-shadow:0px 2px 4px rgba(215,57,59,1);
		// margin-top: 32rpx;
		// margin-left: 36rpx;
	}
	.shiyong11{
		display: flex;
		flex-direction:row;
		margin-top: 32rpx;
		margin-left: 36rpx;
	}
	.shiyong12{
		height:40rpx;
		font-size:28rpx;
		font-weight:400;
		line-height:40rpx;
		text-shadow:0px 2px 4px rgba(255,98,0,1);
		margin-top: 8rpx;
		margin-left: 36rpx;
	}
	.shiyong112{
		width: 48rpx;
		height: 48rpx;
		margin-top: 6rpx;
	}
	.shiyong111{
		height:50rpx;
		font-size:36rpx;
		font-weight:500;
		line-height:50rpx;
		text-shadow:0px 2px 4px rgba(255,98,0,1);
	}
	.shiyong{
		display: flex;
		flex-direction: row;
		height: 384rpx;
		justify-content: space-between;
		color:$uni-text-color-inverse;
	}
	.shiyong1{
		width: 325rpx;
		height: 100%;
		background: url(../../static/image/shiyong.png) no-repeat;
		background-size: 100% 100%;
	}
	.shiyong2{
		height: 100%;
		flex: 1;
		display: flex;
		flex-direction: column;
	}
	.shiyong21{
		height: 192rpx;
		width: 100%;
		background: url(../../static/image/fenxiang.png) no-repeat;
		background-size: 100% 100%;
	}
	.shiyong22{
		width: 100%;
		flex: 1;
		background: url(../../static/image/jifenqiang.png) no-repeat;
		background-size: 100% 100%;
	}
	page{
		background-color: $page-bg-color;
	}
	.lunbo{
		margin-top: 30rpx;
	}
	.content-padding{
		padding-left: 30rpx;
		padding-right: 30rpx;
	}
	
	.status_bar {
	      height: var(--status-bar-height);
	      width: 100%;
		  background-color: #FFFFFF;
	  }
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	.search{
		/* margin-top: 30rpx; */
		display: flex;
		flex-direction: row;
		box-shadow:0px 4px 8px 0px rgba(235,235,235,0.5);
		background-color: #FFFFFF;
	}
	.logo {
		height: 73rpx;
		width: 73rpx;
		margin-top: 10rpx;
		border-radius: 73rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
